import React, { useState } from 'react';
import { View, Text, TouchableOpacity, Modal, StyleSheet } from 'react-native';

interface AgreementScreenProps {
  visible?: boolean;
  onClose?: (agreed: boolean) => void;
}

// 用户协议和隐私政策的内容
const AGREEMENT_TEXT = `
请您充分阅读并理解《用户协议》和《隐私政策》。
我们非常重视您的隐私和个人信息保护。在您使用的过程中，我们会对您的部分个人信息进行收集和使用。
1. 我们会收集您的设备信息、位置信息、软件安装列表等。
`;

const AgreementScreen = ({ visible, onClose }: AgreementScreenProps) => {
  const [agree, setAgree] = useState(false); // 可用于扩展（如带勾选框）

  const handleAgree = () => {
    setAgree(true);
    onClose?.(true);
  };

  const handleDisagree = () => {
    setAgree(false);
    onClose?.(false);
  };

  return (
    <Modal visible={visible} transparent animationType="fade">
      <View style={styles.modalContainer}>
        <View style={styles.modalContent}>
          <Text style={styles.title}>用户协议和隐私政策说明</Text>
          <Text style={styles.agreementText}>{AGREEMENT_TEXT}</Text>

          <TouchableOpacity
            style={styles.disagreeButton}
            onPress={handleDisagree}
          >
            <Text style={styles.buttonText}>不同意</Text>
          </TouchableOpacity>

          <TouchableOpacity style={styles.agreeButton} onPress={handleAgree}>
            <Text style={styles.buttonText}>同意</Text>
          </TouchableOpacity>
        </View>
      </View>
    </Modal>
  );
};

export default AgreementScreen;

// 样式保留在组件内部（也可抽到外层，但建议一起封装）
const styles = StyleSheet.create({
  modalContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0, 0, 0, 0.5)',
  },
  modalContent: {
    width: '80%',
    maxWidth: 400,
    padding: 20,
    backgroundColor: '#fff',
    borderRadius: 10,
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 4,
    elevation: 5,
  },
  title: {
    fontSize: 18,
    fontWeight: 'bold',
    marginBottom: 10,
    textAlign: 'center',
  },
  agreementText: {
    fontSize: 14,
    lineHeight: 20,
    marginBottom: 20,
    color: '#333',
  },
  disagreeButton: {
    backgroundColor: '#f2f2f2',
    paddingVertical: 10,
    paddingHorizontal: 20,
    borderRadius: 5,
    marginBottom: 10,
    alignItems: 'center',
  },
  agreeButton: {
    backgroundColor: '#ff6347', // 橙红色
    paddingVertical: 10,
    paddingHorizontal: 20,
    borderRadius: 5,
    alignItems: 'center',
  },
  buttonText: {
    color: '#fff',
    fontSize: 16,
    fontWeight: 'bold',
  },
  centeredView: {
    flex: 1,
    alignItems: "center",
    marginTop: 180,
  },
  modalView: {
    height: 360,
    margin: 20,
    backgroundColor: "white",
    borderRadius: 20,
    padding: 35,
    alignItems: "center",
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,
    elevation: 5,
  },
  openButton: {
    backgroundColor: "#f0685c",
    borderRadius: 20,
    padding: 10,
    elevation: 2,
    width: 260,
    marginTop: 10,
  },
  agree: {
    color: "white",
    fontSize: 20,
    fontWeight: "bold",
    textAlign: "center",
  },
  agreement: {
    flex: 1,
    overflow: "scroll",
    marginBottom: 15,
  },
  refused: {
    color: "#888",
    fontSize: 20,
    fontWeight: "bold",
    textAlign: "center",
  },
  content: {
    fontSize: 16,
  },
  highLight: {
    color: "#ec6f59",
  },
});
